package com.grow.greenhouse.controller;

import com.grow.greenhouse.common.BaseResponse;
import com.grow.greenhouse.common.ErrorCode;
import com.grow.greenhouse.domain.Feedback;
import com.grow.greenhouse.domain.request.FeedbackRequest;
import com.grow.greenhouse.exception.BusinessException;
import com.grow.greenhouse.service.FeedbackService;
import com.grow.greenhouse.utils.ResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/feedback")
public class FeedBackController {

    @Resource
    private FeedbackService feedbackService;

    @PostMapping("/send")
    public BaseResponse<String> sendFeedBack(@RequestBody FeedbackRequest feedbackRequest,
                                               HttpServletRequest request)
    {
        if(feedbackRequest == null)
        {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"反馈内容为空");
        }
        String send = feedbackService.sendFeedBack(feedbackRequest,request);
        return ResultUtils.success(send);
    }
}
